package com.lnsf.bookstore.system.order.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.github.pagehelper.PageInfo;
import com.lnsf.bookstore.common.dto.ResultSuccessDto;
import com.lnsf.bookstore.system.order.service.OrderService;
import com.lnsf.bookstore.system.order.vo.Order;
import com.lnsf.bookstore.system.orderDetail.service.OrderDetailService;
import com.lnsf.bookstore.system.orderDetail.vo.OrderDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/order")
public class OrderController {

	@Autowired
    private OrderService orderService;

	@Autowired
    private OrderDetailService orderDetailService;

    @RequestMapping("/v_list.do")
    public String list(HttpServletRequest request, ModelMap modelMap){
        System.out.println("order.....");
        return "admin/order/order";
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public Object queryAll(@RequestParam Map<String, Object> params,Order order) {
        PageInfo<Order> list = orderService.selectAll(params,order);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("page",list);
        return map;
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @ResponseBody
    public Object info(@PathVariable("id") Integer id) {
        Map<String, Object> map = new HashMap<String, Object>();
        Order order = orderService.selectByOId(id);
        map.put("order", order);
        return map;
    }

    /**
     * 发货
     * @param order
     * @return
     */
    @RequestMapping("/sendGoods")
    @ResponseBody
    public Object sendGoods(@RequestBody Integer id) {
        Order order = orderService.selectByOId(id);
        orderService.sendBooks(order);
        return new ResultSuccessDto("发货成功");
    }

    /**
     * 修改
     * @param order
     * @return
     */
    @RequestMapping("/update")
    @ResponseBody
    public Object update(@RequestBody Order order) {
        System.out.println("aaaaa");
        orderService.update(order);
        return new ResultSuccessDto("更改成功，测试而已");
    }
}
